import { Component, OnInit } from '@angular/core';
import { User } from '../model/user';
import { HttpClient } from '@angular/common/http';
import 'rxjs/add/operator/debounceTime';
import { Result } from '../model/result';
import { Router } from '@angular/router';
import { UserService } from '../service/user.service';


@Component({
  selector: 'app-registersocialuser',
  templateUrl: './registersocialuser.component.html',
  styleUrls: ['./registersocialuser.component.css']
})
export class RegistersocialuserComponent implements OnInit {
  public user: User = new User();
  confirmpassword = '';
  error = '';
  constructor(public http: HttpClient, public router: Router, public userService: UserService) {
  }

  ngOnInit() {
  }

  register() {
    if (this.user.password !== this.confirmpassword) {
      this.error = '密码和确认密码不一致';
      return;
    }
    // tslint:disable-next-line:no-shadowed-variable
    this.http.post('/social/user', this.user).subscribe((result: Result) => {
      if (result.error === '') {
        this.router.navigateByUrl('/user/login');
      } else {
        this.error = result.error;
      }
    });
  }


}
